public class Segment {

	String name;
	Point a, b;
	

	public Segment(Point a, Point b, String name) {
		this.a = a;
		this.b = b;
		this.name = name;
	}

	public Point getA() {
		return a;
	}

	public void setA(Point a) {
		this.a = a;
	}

	public Point getB() {
		return b;
	}

	public void setB(Point b) {
		this.b = b;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Segment "+ name +" from " + a.toString() + " to " + b.toString();
	}

	public static Object deserialize(String s) {
		java.util.StringTokenizer objectString = new java.util.StringTokenizer(
				s, ";");	
		objectString.nextToken();
		Dispatcher dispatcher = new Dispatcher();
		
		String segName = objectString.nextToken();
		java.util.StringTokenizer segNameToken = new java.util.StringTokenizer(
				segName, ":");
		segNameToken.nextToken();
		segNameToken.nextToken();
		
		String _name = segNameToken.nextToken();	
		
		String className= objectString.nextToken();
		
		Point _a = null;
		Point _b = null;
		
		if(className.equals("geometry.Point")){
			String serialized = "";
			int nbFields = Point.class.getDeclaredFields().length;
			
			for(int i=0; i<nbFields; i++)
				serialized+=objectString.nextToken()+";";
			
			_a = (Point) Point.deserialize(serialized);			
		}else{
			String temp = "";
			while(objectString.hasMoreTokens()){
				temp+=objectString.nextToken()+";";
			}
			_a = (Point) dispatcher.type(temp);
			
		}
		
		className= objectString.nextToken();
		if(className.equals("geometry.Point")){
			String serialized = "";
			int nbFields = Point.class.getDeclaredFields().length;
			
			for(int i=0; i<nbFields; i++)
				serialized+=objectString.nextToken()+";";
			
			_b = (Point) Point.deserialize(serialized);			
		}
		else{
			
			String temp = "";
			while(objectString.hasMoreTokens()){
				temp+=objectString.nextToken()+";";
			}
			_b = (Point) dispatcher.type(temp);
		}		
		
		return new Segment(_a, _b, _name);
	}
}